package com.ruiyian.web.controller.system;


import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.system.domain.ServerEq;
import com.ruiyian.system.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chong
 * @email 673426164@qq.com
 * @create 2021/8/24
 * Desc: 服务
 */
@RestController
@RequestMapping("/system/server")
public class SysServerController extends BaseController {

    @Autowired
    private ServerService serverService;

    /**
     * 分页
     * @param server
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ServerEq server) {
        startPage();
        List<ServerEq> list = serverService.selectList(server);
        return getDataTable(list);
    }

    /**
     * 所有
     * @param server
     * @return
     */
    @PostMapping(value = "/listAll")
    public AjaxResult listAll(@RequestBody ServerEq server) {
        List<ServerEq> list = serverService.selectList(server);
        return AjaxResult.success(list);
    }
    /**
     * 添加
     * @param server
     * @return
     */
    @PostMapping(value = "/save")
    public AjaxResult add(@RequestBody ServerEq server) {
        if(server.getId()==null){
            serverService.save(server);
        }else {
            serverService.update(server);
        }
        return AjaxResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping(value = "/delete")
    public AjaxResult delete(@RequestBody Long id) {
        serverService.delete(id);
        return AjaxResult.success();
    }

    /**
     * 根据id获取对象
     * @param id
     * @return
     */
    @PostMapping(value = "/findOne")
    public AjaxResult findOne(@RequestBody Long id) {
        ServerEq one = serverService.findOne(id);
        return AjaxResult.success(one);
    }
}
